<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="./../template/WorkspaceTemplate.xhtml">

    <ui:define name="top">

    </ui:define>

    <ui:define name="left">

    </ui:define>

    <ui:define name="right">

    </ui:define>

    <ui:define name="content">
        <style>
            .ui-state-highlight.ui-selected {
                color: blueviolet;
            }
        </style>
        <h2>View Credit Account</h2>

        <h:form id="creditAccountForm">
            <p:panel style="height: 250px">
                <p:messages />
                <h:panelGrid columns="3" cellpadding="10">
                    <h:outputLabel style="font-weight: bold" value="Client Id: "/>
                    <h:outputText id="clientId" value="#{caManagerBean.ca.customer.clientId}"/>
                    <h:outputText value=""/>
                    <h:outputLabel style="font-weight: bold" value="Enter Customer: "/>
                    <h:inputText required="true" requiredMessage="Please select customer" id="companyName" value="#{caManagerBean.ca.customer.companyName}"/>
                    <p:commandButton oncomplete="customerDialog.show();" image="ui-icon ui-icon-search"/>   
                </h:panelGrid>
                <p:commandButton id="button" value="Next" update="creditAccountForm" action="#{caManagerBean.viewCreditAccount()}"/>
            </p:panel>
        </h:form>


        <p:dialog header="Search Customers" widgetVar="customerDialog" showEffect="fade" hideEffect="fade" height="600" width="800">  
            <h:form id="customerForm">
                <p:dataTable var="customer" value="#{scManagerBean.customers}" emptyMessage="No clients found with given criteria"  selection="#{caManagerBean.ca.customer}" selectionMode="single">

                    <f:facet name="header">
                        <p:outputPanel>
                            <h:outputText value="Search all fields:" />
                            <p:inputText id="globalFilter" onkeyup="ctbl.filter()" style="width:150px" />
                        </p:outputPanel>
                    </f:facet>

                    <p:column filterBy="#{customer.companyName}" 
                              headerText="Company Name" footerText="contains"
                              filterMatchMode="contains">
                        <h:outputText value="#{customer.companyName}" />
                    </p:column>

                    <p:column filterBy="#{customer.clientId}" headerText="Client Id" footerText="contains">
                        <h:outputText value="#{customer.clientId}" />
                    </p:column>

                    <p:column filterBy="#{customer.category}" headerText="Client Category" footerText="exact"
                              filterOptions="#{sslManagerBean.categoryOptions}"
                              filterMatchMode="exact">
                        <h:outputText value="#{customer.category}" />
                    </p:column>
                </p:dataTable>
                <br/>
                <p:commandButton value="Select Customer" update="creditAccountForm:clientId creditAccountForm:companyName creditAccountForm:creditGroupDetails" oncomplete="customerDialog.hide()"/>

            </h:form>
        </p:dialog>

    </ui:define>

    <ui:define name="bottom">

    </ui:define>

</ui:composition>
